package com.offcn.test;

import com.offcn.bean.Student;
import com.offcn.mapper.StudentMapper;
import com.offcn.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class Demo01 {
    @Test
    public void test(){
        SqlSession session = MybatisUtils.getSession();
        // alt+enter+enter：生成返回值
        StudentMapper mapper = session.getMapper(StudentMapper.class);
        List<Student> students = mapper.getStudents();
        for (Student student:students){
            System.out.println(student.toString());
        }
    }

    // 查询所有的学生信息（多表查询）第二种方法:在sql语句上做文章
    @Test
    public void test2(){
        SqlSession session = MybatisUtils.getSession();
        // alt+enter+enter：生成返回值
        StudentMapper mapper = session.getMapper(StudentMapper.class);
        List<Student> students = mapper.getStudents2();
        for (Student student:students){
            System.out.println(student.toString());
        }
    }
}
